package com.nanshenycd.util;

import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.stereotype.Component;

@Component
public class MD5Util {
    public static String md5(String src){
        return DigestUtils.md5Hex(src);
    }

    private static final String salt="1a2b3c4d";

    public static String inputPassToFromPass(String inputPass){
        String str="" + salt.charAt(0) + salt.charAt(2) + inputPass + salt.charAt(5) + salt.charAt(4);
        System.out.println("1======="+md5(str));
        return md5(str);
    }

    //md5(str)
    public static String second(String formpass,String salt){
        String str=""+salt.charAt(0)+salt.charAt(2)+formpass+salt.charAt(5)+salt.charAt(4);
        System.out.println("2========"+md5(str));
        return md5(str);
    }


    //后端真正调用的方法
    public static String result(String orignal,String salt){
        //dbPass
        return second(inputPassToFromPass(orignal),salt);
    }

    public static void main(String[] args) {
//        System.out.println(inputPassToFromPass("1234556"));
//        System.out.println(second(inputPassToFromPass("1234556"),salt));
        System.out.println("================================");
        System.out.println(result("123456",salt));
    }

}
